<?php


namespace app\admin\controller;


use app\admin\model\Wiki as WikiModel;
use app\common\controller\AdminController;
use think\Exception;
use think\facade\Request;

/**
 * 法拍百科
 * Class Wiki
 * @package app\admin\controller
 */
class Wiki extends AdminController {

    public $resubmitLock = ['addpost', 'del', 'editpost'];

    public $levelConfig = [
        1 => ['getlist', 'wherelist','addget','editget'],
        2 => ['addpost', 'del', 'editpost'],
        4 => [],
        8 => []
    ];


    public function whereList() {
        try {
            $params = $this->checkParams('');
            $list = [
                ['key' => 1, 'val' => "新手必看"],
                ['key' => 2, 'val' => "竞拍攻略"],
                ['key' => 3, 'val' => "法拍资讯"],
            ];
            return $this->resData('success', $list);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 列表
     * @return false|string
     */
    public function getList() {
        try {
            $params = $this->checkParams('');
            if ($params === false) return $this->resErr();
            $list = WikiModel::getList($params);
            return $this->resData('success', $list);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 添加获取
     * @return false|string
     */
    public function addGet() {
        try {
            $list = [
                ['key' => 1, 'val' => '新手必看'],
                ['key' => 2, 'val' => '竞拍攻略'],
                ['key' => 3, 'val' => '法拍资讯']
            ];
            return $this->resData('success', $list);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 添加提交
     * @return false|string
     */
    public function addPost() {
        try {
            $params = $this->checkParams('detail_url,cover,title,type');
            if ($params === false) return $this->resErr();
            $res = WikiModel::post($params);
            if (!$res) return $this->resErr();
            else return $this->resData('添加成功', []);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 编辑获取
     * @return false|string
     */
    public function editGet() {
        try {
            $params = $this->checkParams('id');
            if ($params === false) return $this->resErr();
            $res = WikiModel::info($params['id'], $info);
            if (!$res) return $this->resErr();
            $list = [
                ['key' => 1, 'val' => '新手必看'],
                ['key' => 2, 'val' => '竞拍攻略'],
                ['key' => 3, 'val' => '法拍资讯']
            ];
            return $this->resData('success', compact('info', 'list'));
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 编辑提交
     * @return false|string
     */
    public function editPost() {
        try {
            $params = $this->checkParams('detail_url,cover,title,id');
            if ($params === false) return $this->resErr();
            $res = WikiModel::post($params);
            if (!$res) return $this->resErr();
            else return $this->resData('操作成功', []);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 删除
     * @return false|string
     */
    public function del() {
        try {
            $params = $this->checkParams('id');
            if ($params === false) return $this->resErr();
            $res = WikiModel::del($params);
            if (!$res) return $this->resErr();
            else return $this->resData('操作成功', []);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }
}
